<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8" />
    <title>后台管理_资源共享平台</title>
    <link rel="stylesheet" href="/layui/css/layui.css"/>
    <link rel="stylesheet" href="/css/style.css"/>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo"><a href="/admin" style="color: gray">资源共享平台-后台管理</a></div>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item"><a href="javascript:history.back();"><i class="layui-icon layui-icon-return">&nbsp;返回上一页</i></a></li>
            <li class="layui-nav-item"><a onclick="refreshFrame()"><i class="layui-icon layui-icon-refresh">&nbsp;刷新当前页</i></a></li>
            <li class="layui-nav-item">
                <a href="javascript:;">
                    <img class="layui-nav-img" th:src="${'/avatars/' + session.currentUser.avatar}" th:text="${session.currentUser.username}"/>
                </a>
            </li>
        </ul>
    </div>
    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree" lay-filter="test">
                <li class="layui-nav-item layui-nav-itemed">
                    <a class="" href="javascript:;">导航菜单</a>
                    <dl class="layui-nav-child">
                        <dd><a href="javascript:openPage('res.html')">资源管理</a></dd>
                        <dd><a href="javascript:openPage('resType.html')">资源类别管理</a></dd>
                        <dd><a href="javascript:openPage('user.html')">用户管理</a></dd>
                        <dd><a href="javascript:openPage('comment.html')">评论管理</a></dd>
                        <dd><a href="javascript:openPage('link.html')">友情链接管理</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item layui-nav-itemed">
                    <a href="javascript:;">系统管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="javascript:genAllIndex()">生成所有资源索引</a></dd>
                        <dd><a href="javascript:showModifyPasswordDialog();">修改密码</a></dd>
                        <dd><a href="javascript:logout();">安全退出</a></dd>
                    </dl>
                </li>
            </ul>
        </div>
    </div>
    <div class="layui-body">
        <iframe id="pageFrame" frameborder="0" scrolling="auto" style="width:100%;height:98%" src="/admin/default.html"></iframe>
    </div>
    <!-- 底部固定区域 -->
    <div class="layui-footer">
        Copyright © 2022-2028 xxx 版权所有
    </div>
</div>

<script src="/layui/layui.js"></script>
<script src="/js/common.js"></script>
<script type="text/javascript" th:inline="javascript">
    /*<![CDATA[*/
    let $, layer;
    layui.use(['layer'], function () {
        $ = layui.jquery,
            layer = layui.layer;
    });

    function refreshFrame() {
        document.getElementById('pageFrame').contentWindow.location.reload(true);
    }

    function openPage(page) {
        $("#pageFrame").attr("src", "/admin/" + page);
    }

    function showModifyPasswordDialog() {
        layer.open({
            type: 2,
            title: '修改密码',
            area: ['480px', '400px'],
            content: '/user/modifyPassword.html'
        });
    }

    function logout() {
        layer.confirm("您确定退出系统吗", {
            title: "系统提示",
            btn: ['确定', '取消']
        }, function () {
            window.location.href = "/admin/user/logout";
        }, function () {

        });
    }

    function genAllIndex() {
        layer.confirm("您确定要重新生成所有资源的索引吗？<br/>(如需生成，请先删除原来的资源索引)", {
            title: "系统提示",
            btn: ['确定', '取消']
        }, function () {
            layer.closeAll('dialog');
            layer.load(1, {
                shade: [0.1, '#fff'] //0.1透明度的白色背景
            });
            $.post("/admin/res/genAllIndex", {}, function (result) {
                if (result) {
                    layer.closeAll('loading');
                    layer.msg("生成成功！");
                } else {
                    layer.msg("生成失败，请联系管理员！");
                }
            }, "json");
        }, function () {

        });
    }
    /*]]>*/
</script>
</body>
</html>